home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-27 | 13.0 KB | 292 lines | [TEXT/MSET] |
- CLASS DEFINITION
-
- :CLASS -- : name super{ cname1 cname2 } opt
- Begins definition of a new class. One or more classnames can be
- designated as superclass(es). There are optional parameters that may
- also be declared after the superclass list, including n INDEXED, LARGE,
- and GENERAL.
- ;CLASS -- Ends definition of a class.
-
- SUPER{ -- : cname1 cname2 } opt
- Used to declare the superclass(es) when defining a class. See :class.
-
- GENERAL --
- Optional class declaration that will allow late binding when this class
- is used as an ivar. But note that GENERAL classes may not be used to
- map ivars to Mac toolbox calls because the class header information will
- be included. INDEXED classes are automatically GENERAL.
- LARGE --
- Sets the "large" option on an indexed class, allowing the number of
- elements to be greater than 32K.
- INDEXED n --
- Sets a class and its subclasses to indexed, of element byte width n.
- Used after the superclass declaration list when defining a new class.
- Note that when instantiating an indexed class, you MUST precede the
- instance name with the number of elements you wish that instance to
- have. Also note that all indexed classes are automatically declared to
- be GENERAL, so you may not used indexed classes to map into toolbox
- calls. Also, n must be < 32K (see LARGE).
-
- :M -- : name:
- Begins definition of a method within a class. Note that name: MUST end
- with a colon (:).
- ;M -- Ends definition of a method in a class.
-
- PRIVATE --
- Use within a class definition. Makes the following methods private—that
- is, they will be accessible from within this class or any of its
- subclasses, but not from anywhere else. The criterion is simply that a
- call to Self of Super may access a private method, but nothing else can.
- Note that for this reason you can't late-bind to a private method, even
- if you do it from within the class itself.
- PUBLIC --
- Makes the following methods public—that is, they will be accessible from
- anywhere. PRIVATE and PUBLIC may be used any number of times within the
- one class definition. Methods are initially public when a class
- compilation starts.
-
- CallFirst -- : methodname:
- The next method definition will always execute the method indicated by
- methodname: BEFORE it is executed by a subclass. Provides a way for
- superclasses to limit the extent to which subclasses may override a
- method.
- CallLast -- : methodname:
- The next method definition will always execute the method indicated by
- methodname: AFTER it is executed by a subclass. Provides a way for
- superclasses to limit the extent to which subclasses may override a
- method.
-
- SELF -- obj
- Object reference to self. Only used in a class definition. SELF is not
- necessarily the same as ^BASE, because of multiple inheritance.
- SUPER -- obj
- Use within a class method definition to refer to self, an instance of
- the class, but the superclass method will be invoked.
-
-
- LATE BINDING
- [ --
- Begins an expression with a late bound message that computes the address
- of the object to recieve the message. e.g. get: [ 0 at: anArray ] .
- This is an alternative syntax to that provided by **, [], and [self].
- ] -- See above.
-
- note that [SELF], [], and ** are all synonyms.
- [SELF] obj selid --
- Late binds whatever is on the stack to the given method. e.g. obj
- get: [self] . You must be sure that obj really does point to an
- object.
- [] ^obj selid -- See above.
- ** ^obj selid -- See above.
-
-
- STANDARD METHODS
-
- CLASSINIT: --
- Our standard constructor method. The default message that is ALWAYS
- sent to an object at time of instantiation, even ivars. Note that if
- parameters are to be included for a classinit: for an INDEXED class, the
- #elements must precede those parameters (#elems must be top item on
- stack) at instantiation time (read that again). Note that for class
- object classinit: is a null method, that is it does nothing.
-
- ADDR: -- ^base
- Returns the address of the beginning of an object's ivars.
- CLASS: -- class Returns the class pointer for an object.
- COPYTO: obj --
- Copies the ivar part of the passed in object to self. Doesn't check
- type - be careful.
- DUMP: -- Performs a formatted dump of a class.
- LENGTH: -- len
- Gets total length of object. Length will include class header
- information only if class is of type GENERAL. Otherwise, length is
- merely the length of the ivar data field(s).
- PRINT: -- Use to display a class, default is just a DUMP:.
- RELEASE: --
- Our standard destructor method. Any objects that allocate heap storage
- will redefine this appropriately. Our convention is that an object will
- release ALL its storage when it gets a release: message. Other methods
- can be provided to partly release storage, as needed.
-
-
-
- CONSOLE INSPECTION
-
- .CLASS: -- A method. Prints the name of the class of the given object.
- .ID: -- A method. Prints the name of the given object, if it has a name.
-
-
- MISCELLANEOUS
-
- BYTES n -- : ivarname
- Bytes is used as the ivar allocation primitive for basic classes.
- Allocates n bytes as a named instance variable of an object. You can
- use bytes to map a Toolbox data structure as an object when named access
- to some of the fields is not needed (but you must know the proper
- length).
-
- BIND_WITH obj --<selector> obj-modified cfa
- If you are late-binding in a loop, it can be much faster if you do the
- bind just once, then reuse the resulting cfa each time in the loop.
- This way you only have to perform the method search once. To bind
- initially and get the cfa, use BIND_WITH. Usage: (saveCfa and ^obj-mod
- are values or locals). (get object's address) bind_with someSelector:
- -> saveCfa -> ^obj-mod. (in the loop) ^obj-mod saveCfa ex-method.
- SET_CLASS obj theClass --
- SET_CLASS is a utility word used to patch nucleus objects when their
- classes are defined in higher-level files. Actually it could be used to
- change the class of any object, if anyone is silly enough to want to do
- that.
- SET_TO_CLASS objPtr -- : cname
- If you need to declare the object pointer before the class exists, use
- SET_TO_CLASS once the class is defined, thus: ' someOP set_to_class
- someClass.
-
-
- STANDARD CLASSES
-
- (COL) -- : name
- Collections are ordered lists with a current size. We implement them by
- multiply inheriting the generic (COL) class with the array class of the
- appropriate width. We use a few tricks to avoid late binding to self in
- loops.
- ARRAY #elems -- : name
- The basic 4-byte cell one-dimension array. Class is INDEXED.
- BOOL -- : name
- Subclass of byte. Note that since the datalength of aMops class bool is
- 1, this class should not be used to map into a Toolbox record of type
- BOOLEAN because the Pascal type boolean has a length of 2 (Use the Mops
- class INT for a Toolbox boolean).
- BYTE -- : name A standard 1-byte variable class.
- DICADDR -- : name
- DICADDR is a relocatable dictionary address class - use to store
- non-executable dictionary addresses.
- HANDLE -- : name The standard class for handles.
- HANDLEARRAY #elems -- : name
- HANDLEARRAY and HANDLELIST are for the implementation of collections of
- heap-based objects. HandleArray has normal array properties. Use
- HandleList if the number of elements may grow arbitrarily large, and if
- indexing isn't so important. HandleArray also includes methods to allow
- the array to be used as a stack - needed for FileList.
- HANDLELIST #elems -- : name
- HANDLELIST allows the implementation of a list of heap-based objects.
- Unlike HANDLEARRAY, the list can be of indefinite length. We use a heap
- block to store the handles to the objects contiguously, rather than have
- a separate block for each handle and link them together. This saves on
- memory overhead and reduces the number of memory manager calls. It also
- reflects the assumption that insertions and deletions into the middle of
- the list will be infrequent, as these could be more inefficient than
- with a linked scheme. We expect that elements will normally be added to
- the end, and probably not removed at all, or not very often.
- INDEXED-OBJ -- : name
- Class INDEXED-OBJ is the generic superclass for all arrays. Here we
- define the general indexed methods, which apply regardless of indexed
- width.
- LONGWORD -- : name Generic superclass for var, handle etc.
- OBJHANDLE -- : name
- An OBJHANDLE is a handle that points to an object in the heap.
- OBJPTR -- : name
- An object pointer is a "low-level" entity, rather like a value. The
- syntax for object pointers is: objPtr anObjptr class_is theClass
- OBJ_ARRAY #elems -- : name
- OBJ_ARRAY is a generic superclass which makes it easy to generate an
- array of objects of a given class. Just define a new class which
- multiply inherits from the given class (or classes) and OBJ_ARRAY (which
- must come last). This will add an indexed section to each object of the
- new class, with elements wide enough to contain objects of the original
- class. Then SELECT: "switches in" the selected element to be the
- "current" element, and all the normal methods of the class can then be
- used. Note the use of"32767 indexed" in the class definition.
- ORDERED-COL #elems -- : name
- Ordered-Collection is a collection of 4-byte cells. A subclass of (col)
- and array.
- PTR -- : name A standard class. For toolbox pointers.
- RESOURCE -- : name
- Provides basic support for Toolbox resources.
- SEQUENCE #elems -- j : name
- A generic superclass for classes which have multiple items which
- frequently need to be looked at in sequence. At present the main
- function of Sequence is to implement the EACH: method, which makes it
- very simple to deal with each element. Sequence can be multiply
- inherited with any class which implements the FIRST?: and NEXT?:
- methods. The actual implementation details are quite irrelevant, as
- long as these methods are supported.
- VAR -- : name
- The standard variable class. Subclass of longword that adds the +: and
- -: methods. Useful as an ivar that maps into a Toolbox LONGINT record
- structure.
- X-ADDR -- : name
- X-ADDR is an executable dictionary address class. The only significant
- difference to DicAddr is that there is an Exec: method and no Get:
- method. But if we ever have to separate code and data, having a
- separate class could prove very useful.
- X-ARRAY #elems -- : name
- A subclass of ARRAY, can execute its elements (which are cfas of Mops
- words).
- X-COL #elems -- : name
- X-COL is a collection of executable word addresses. A subclass of (col)
- and x-array.
-
-
- PRIMITIVES
-
- ^BASE -- addr
- Addr is the base address of the private data of the object. Only used
- in a class definition. Same as addr: self.
- OBJ -- obj
- Called from within an inline method. Passes the object's base and
- displacement to Handlers to generate the correct address. Optimization
- will then apply.
- OBJECT -- class
- The root class of all classes. Only used as a declared superclass when
- defining a new class. Note that class object has the pre-defined
- methods class:, .id:, .class:, addr:, length:, copyto:, classinit:,
- release:, dump:, and print:. So ALL objects possess these methods.
- Some of these methods do nothing, for class object.
- OBJLEN -- n Computes total data length of current object.
- CHKSAME obj -- obj
- A check that two objects are of exactly the same class. Aborts with
- error message if not.
- CHKCLASS cfa -- cfa
- Aborts and issues error message if the cfa does not refer to a class.
- ?>CLASS obj -- class
- Converts the pointer to an object to a pointer to its class. Aborts if
- failure.
- ?CLASS -- Error if not compiling a class definition.
- CL1 -- Cleans up the class compiler data on an abort.
- CL>LEN #els class -- #els len
- Gets data length of object given #els and class.
- DFA class -- dfa
- Given a pointer to a class, returns the data field address. First 2
- bytes are the data length, second 2 bytes are the width of the indexed
- elements.
- DLEN&XWID class -- dlen xwid
- Given a class pointer, retuns the ivar datalength and width of the
- indexed elements.
- EXMID obj selID --
- Executes a method given its sel ID. Used in late binding.
- FFA ^class -- ffa
- Given a pointer to a class, returns the flag field address.
- FINDM selID class -- offs cfa Finds a method in a class.
- GETDLEN obj -- n Gets length of object's named ivars.
- IFA class -- ifa
- Given a pointer to a class, returns the ivar field address.
- IVFINDM selID ^ivar -- offs cfa Looks for a method in
- IX -- ifa
- Called from within an inline method. Compiles code to generate the
- indexed address.
- META -- class
- META is the super class of Object - top of all inheritance.
- MFA class -- mfa Given a pointer to a class, returns the methods field address.
- RELCNT -- n
- A value. For testing - counts release: msgs to make sure we're
- releasing everything.
- SFA class -- sfa
- Given a pointer to a class, returns the superclass field address, which
- is an N-way pointer.
- SUPER( -- : cname1 cname2 } opt Synonym for super{.
- XWID class -- xwid Given a class pointer, retuns the width of the indexed elements.
- ^CLASS -- class Addr of the class we're currently compiling.
- ^DLEN obj -- dfa Returns the dfa for the given object.
- ^ELEM idx -- addr Leaves addr of indexed element.
-